<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IPv4协议数据包格式详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .field-number {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-weight: 700;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .section-divider {
            background: linear-gradient(to right, transparent, #667eea, transparent);
            height: 1px;
            margin: 3rem 0;
        }
        
        .bit-indicator {
            background: #f3f4f6;
            border-radius: 20px;
            padding: 0.25rem 0.75rem;
            font-size: 0.875rem;
            font-weight: 500;
            color: #4b5563;
            display: inline-block;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        
        .field-card {
            background: white;
            border-radius: 16px;
            padding: 2rem;
            position: relative;
            overflow: hidden;
        }
        
        .field-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center animate-fadeInUp">
            <h1 class="text-5xl md:text-6xl font-bold mb-6" style="font-family: 'Noto Serif SC', serif;">
                IPv4协议数据包格式
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                深入解析互联网协议第四版的数据包结构，理解网络通信的基石
            </p>
            <div class="mt-8 flex justify-center space-x-4">
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-network-wired mr-2"></i>网络协议
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-cube mr-2"></i>14个核心字段
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                    <i class="fas fa-layer-group mr-2"></i>分层架构
                </span>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12 animate-fadeInUp">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">I</span>Pv4协议的数据包格式中包含多个字段，每个字段都有特定的作用，用来确保数据包能够正确地被路由和传输。这些字段共同构成了互联网通信的基础框架，让我们深入了解每个字段的具体功能。
            </p>
        </div>

        <!-- Visual Diagram -->
        <div class="bg-white rounded-2xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-center text-gray-800">IPv4数据包结构图</h2>
            <div class="mermaid">
                graph TB
                    A[IPv4数据包] --> B[固定头部<br/>20字节]
                    A --> C[可选部分<br/>0-40字节]
                    A --> D[数据部分<br/>可变长度]
                    
                    B --> E[版本 4位]
                    B --> F[首部长度 4位]
                    B --> G[区分服务 8位]
                    B --> H[总长度 16位]
                    B --> I[标识 16位]
                    B --> J[标志 3位]
                    B --> K[片偏移 13位]
                    B --> L[TTL 8位]
                    B --> M[协议 8位]
                    B --> N[校验和 16位]
                    B --> O[源地址 32位]
                    B --> P[目标地址 32位]
                    
                    C --> Q[选项]
                    C --> R[填充]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#f3f4f6,stroke:#667eea,stroke-width:2px
                    style C fill:#f3f4f6,stroke:#667eea,stroke-width:2px
                    style D fill:#f3f4f6,stroke:#667eea,stroke-width:2px
            </div>
        </div>

        <!-- Fields Grid -->
        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-12">
            <!-- Field 1: Version -->
            <div class="field-card card-hover">
                <div class="flex items-start mb-4">
                    <span class="field-number text-4xl mr-4">01</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">版本（Version）</h3>
                        <span class="bit-indicator"><i class="fas fa-microchip mr-1"></i>4位</span>
                    </div>
                </div>
                <p class="text-gray-600 leading-relaxed">
                    指示IP协议的版本号，对于IPv4，该字段的值为4。这个字段用来区分不同版本的IP协议，例如IPv4和IPv6。
                </p>
            </div>

            <!-- Field 2: IHL -->
            <div class="field-card card-hover">
                <div class="flex items-start mb-4">
                    <span class="field-number text-4xl mr-4">02</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">首部长度（IHL）</h3>
                        <span class="bit-indicator"><i class="fas fa-microchip mr-1"></i>4位</span>
                    </div>
                </div>
                <p class="text-gray-600 leading-relaxed">
                    表示IP数据包头部的长度，以32位（4字节）为单位。最小值是5（表示20字节的最小头部长度），表示没有选项字段。如果有选项字段，这个值会更大。
                </p>
            </div>

            <!-- Field 3: DS -->
            <div class="field-card card-hover">
                <div class="flex items-start mb-4">
                    <span class="field-number text-4xl mr-4">03</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">区分服务（DS）</h3>
                        <span class="bit-indicator"><i class="fas fa-microchip mr-1"></i>8位</span>
                    </div>
                </div>
                <p class="text-gray-600 leading-relaxed">
                    包括服务类型和流量类别字段。用于指定数据包的优先级和服务质量（QoS），例如VoIP通话可标记为延迟敏感，文件传输可标记为低优先级。
                </p>
            </div>

            <!-- Field 4: Total Length -->
            <div class="field-card card-hover">
                <div class="flex items-start mb-4">
                    <span class="field-number text-4xl mr-4">04</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">总长度</h3>
                        <span class="bit-indicator"><i class="fas fa-microchip mr-1"></i>16位</span>
                    </div>
                </div>
                <p class="text-gray-600 leading-relaxed">
                    表示整个IP数据包的长度，包括头部和数据部分，单位为字节。最大值是65535，表示IP数据包的最大长度为65535字节。
                </p>
            </div>

            <!-- Field 5: Identification -->
            <div class="field-card card-hover">
                <div class="flex items-start mb-4">
                    <span class="field-number text-4xl mr-4">05</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">标识</h3>
                        <span class="bit-indicator"><i class="fas fa-microchip mr-1"></i>16位</span>
                    </div>
                </div>
                <p class="text-gray-600 leading-relaxed">
                    唯一标识发送端在一定时间内发送的每个数据包。用于数据包的分片和重组，确保所有片段可以正确地被识别和重组。
                </p>
            </div>

            <!-- Field 6: Flags -->
            <div class="field-card card-hover">
                <div class="flex items-start mb-4">
                    <span class="field-number text-4xl mr-4">06</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">标志</h3>
                        <span class="bit-indicator"><i class="fas fa-microchip mr-1"></i>3位</span>
                    </div>
                </div>
                <p class="text-gray-600 leading-relaxed mb-3">
                    用于控制或识别分片，包含三个标志位：
                </p>
                <ul class="space-y-2 text-gray-600">
                    <li><i class="fas fa-flag text-purple-500 mr-2"></i>第一位：保留位，通常为0</li>
                    <li><i class="fas fa-ban text-purple-500 mr-2"></i>第二位DF：禁止分片标志</li>
                    <li><i class="fas fa-plus text-purple-500 mr-2"></i>第三位MF：更多分片标志</li>
                </ul>
            </div>

            <!-- Field 7: Fragment Offset -->
            <div class="field-card card-hover">
                <div class="flex items-start mb-4">
                    <span class="field-number text-4xl mr-4">07</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">片偏移</h3>
                        <span class="bit-indicator"><i class="fas fa-microchip mr-1"></i>13位</span>
                    </div>
                </div>
                <p class="text-gray-600 leading-relaxed">
                    指示每个分片在原始数据包中的相对位置。帮助接收端将分片正确地拼装回完整的数据包。
                </p>
            </div>

            <!-- Field 8: TTL -->
            <div class="field-card card-hover">
                <div class="flex items-start mb-4">
                    <span class="field-number text-4xl mr-4">08</span>
                    <div class="flex-1">
                        <h3 class="text-2xl font-bold text-gray-800 mb-2">生存时间（TTL）</h3>
                        <span class="bit-indicator"><i class="fas fa-microchip mr-1"></i>8位</span>
                    </div>
                </div>
                <p class="text-gray-600 leading-relaxed">
                    表示数据包在网络中存活的最大跳数。每经过一个路由器减1，降到0时数据包被丢弃，防止无限循环。